package com.platform.usercenter.controller;

import com.platform.common.core.utils.poi.ExcelUtil;
import com.platform.common.core.web.controller.BaseController;
import com.platform.common.core.web.domain.AjaxResult;
import com.platform.common.core.web.page.TableDataInfo;
import com.platform.common.security.annotation.RequiresPermissions;
import com.platform.usercenter.domain.ContactRelation;
import com.platform.usercenter.service.IContactRelationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 联系人关系Controller
 *
 * @author platform
 * @date 2023-10-08
 */
@RestController
@RequestMapping("/relation")
public class ContactRelationController extends BaseController
{
    @Resource
    private IContactRelationService contactRelationService;

    /**
     * 查询联系人关系列表
     */
    @RequiresPermissions("gen:relation:list")
    @GetMapping("/list")
    public TableDataInfo list( ContactRelation contactRelation)
    {
        startPage();
        List< ContactRelation > list = contactRelationService.selectContactRelationList(contactRelation);
        return getDataTable(list);
    }

    /**
     * 导出联系人关系列表
     */
    @RequiresPermissions("gen:relation:export")
    //@Log(title = "联系人关系", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ContactRelation contactRelation)
    {
        List< ContactRelation > list = contactRelationService.selectContactRelationList(contactRelation);
        ExcelUtil< ContactRelation > util = new ExcelUtil< ContactRelation >( ContactRelation.class);
        util.exportExcel(response, list, "联系人关系数据");
    }

    /**
     * 获取联系人关系详细信息
     */
    @RequiresPermissions("gen:relation:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(contactRelationService.selectContactRelationById(id));
    }

    /**
     * 新增联系人关系
     */
    @RequiresPermissions("gen:relation:add")
    //@Log(title = "联系人关系", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ContactRelation contactRelation)
    {
        return toAjax(contactRelationService.insertContactRelation(contactRelation));
    }

    /**
     * 修改联系人关系
     */
    @RequiresPermissions("gen:relation:edit")
    //@Log(title = "联系人关系", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ContactRelation contactRelation)
    {
        return toAjax(contactRelationService.updateContactRelation(contactRelation));
    }

    /**
     * 删除联系人关系
     */
    @RequiresPermissions("gen:relation:remove")
    //@Log(title = "联系人关系", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(contactRelationService.deleteContactRelationByIds(ids));
    }
}
